package cn.wuqingna.legendgem.loader

import cn.wuqingna.legendgem.suit.Suit
import cn.wuqingna.legendgem.util.info
import cn.wuqingna.legendgem.util.listFile
import cn.wuqingna.legendgem.util.newfolder
import org.bukkit.configuration.file.YamlConfiguration
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.platform.BukkitPlugin

object SuitLoader {
    private val folder = newfolder(BukkitPlugin.getInstance().dataFolder, "suit", listOf("suit.yml"))
    val suit = mutableMapOf<String, Suit>()
    @Awake(LifeCycle.ENABLE)
    fun init(){
        folder.listFile("yml").forEach { file ->
            suit.clear()
            val config = YamlConfiguration.loadConfiguration(file)
            config.getConfigurationSection("").getKeys(false).forEach { tag ->
                val section = config.getConfigurationSection(tag)
                val map = mutableMapOf<String, String>()
                section.getConfigurationSection("custom-data").getKeys(false).forEach { key ->
                    map[key] = section.getString("custom-data.$key")
                }
                suit[tag] = Suit(section.getStringList("text"), section.getString("conditions"), section.getStringList("attributes"), map)
            }
        }
        info(" Loader Suits §c${suit.size}§f.")
    }
}